/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vendingmachine10;

import javax.swing.JFrame;


/**
 *
 * @author Peach
 */
public class VendingControl extends JFrame{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        JFrame frame=new VendingFrame();
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setVisible(true);
    }

}
class VendingFrame extends JFrame{
    public VendingFrame(){
	setTitle("FileViewer");
	setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
	
        /*
	final JTree tree=new JTree(root);
	tree.addTreeSelectionListener(new TreeSelectionListener(){
		public void valueChanged(TreeSelectionEvent event){
			TreePath path=event.getPath();
			Object[] pathRoot=path.getPath();
			String filePath="";
			for(int i=0;i<pathRoot.length-1;i++){
				filePath+=pathRoot[i]+"/";
			}
			filePath+=pathRoot[pathRoot.length-1];
			//DefaultMutableTreeNode selectNode =
			//	(DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); 
			showFileContent(filePath);
			//System.out.println(filePath);
		}
	});
	Container contentPane=getContentPane();
	contentPane.add(new JScrollPane(tree),BorderLayout.WEST);
		
	JMenuBar menuBar=new JMenuBar();
	setJMenuBar(menuBar);
	addMenuBar(menuBar);
    }
	
    public void showFileContent(String file){
        File showFile=new File(file);
	if(showFile.isDirectory()){
		return;
	}else if(showFile.isFile()){
		FileInputStream fileStream=null;
		try {
			fileStream = new FileInputStream(file);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
                BufferedReader reader = new BufferedReader(new InputStreamReader(fileStream));
		String line="";
		try {
                    while((line=reader.readLine())!=null){
                        System.out.println(line);
                    }
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
    }
	
	public void addMenuBar(JMenuBar menuBar){
		JMenu fileMenu =new JMenu("File");
		menuBar.add(fileMenu);
		JMenuItem exitItem=new JMenuItem("Exit");
		exitItem.addActionListener(new
				ActionListener(){
			public void actionPerformed(ActionEvent event){
				System.exit(0);
			}
		});
		fileMenu.add(exitItem);
	}
	
	public void showPath(DefaultMutableTreeNode parent,File file){
		File[] fileList=file.listFiles();
		for(int i=0;i<fileList.length;i++){
			//System.out.println(fileList[i]);
			if(fileList[i].isFile()){
				//System.out.println("file:"+fileList[i].getName());
				node=new DefaultMutableTreeNode(fileList[i].getName());
				parent.add(node);
			}
			else if(fileList[i].isDirectory()){
				//System.out.println("dir:"+fileList[i].getName());
				node=new DefaultMutableTreeNode(fileList[i].getName());
				parent.add(node);
				showPath(node,fileList[i]);
			}
		}
	}
        */ 
    }
 
    private static final int DEFAULT_WIDTH=600;
    private static final int DEFAULT_HEIGHT=400;
        
}